package com.sinosoft.config.jdbc.dataSource;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Auther: zouren
 * @Date: 2019/5/10 14:31
 * @Description:
 */
@Aspect
@Order(-1)// 保证该AOP在@Transactional之前执行
@Component
@Slf4j
public class DataSourceAop {

    @Before("execution(* com.sinosoft.*.entity.dao..*.select*(..)) || execution(* com.sinosoft.*.entity.dao..*.get*(..))|| execution(* com.sinosoft.*.entity.dao..*.query*(..))")
    public void setReadDataSourceType() {
        DataSourceContextHolder.read();
        log.info("dataSource 切换到：Read");
    }

    @Before("execution(* com.sinosoft.*.entity.dao..*.insert*(..)) || execution(* com.sinosoft.*.entity.dao..*.update*(..)) || execution(* com.sinosoft.*.entity.dao..*.delete*(..))")
    public void setWriteDataSourceType() {
        DataSourceContextHolder.write();
        log.info("dataSource 切换到：Write");
    }


}
